﻿Public Class DRUGINTEN

    Dim connect As CONDB = CONDB.NewConnection()
    'Dim connectlocal As conlocal = conlocal.NewConnection
    Dim PROVIDER_Check As New PROVIDERSCLASS

    Private Sub DRUGINTEN_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        SelectDatagridMASDRGINTEN()

        DesignForm(Me)
        DesignGrid(MASDRGINTENGrid)

        PROVIDER_Check.GETHOSEM(CInt(main.txtUserRequest.Text.Trim), Convert.ToString(Me.Tag))
    End Sub

    Private Sub SelectDatagridMASDRGINTEN()
        Dim objSelectDataMasginten As New masdrginten
        Dim MASDRGINTEN As DataTable
        MASDRGINTEN = connect.GetTable(objSelectDataMasginten.selectMasdrginten_)
        MASDRGINTENGrid.PrimaryGrid.DataSource = MASDRGINTEN
    End Sub

    Private Sub MASDRGINTENGrid_CellClick(sender As Object, e As DevComponents.DotNetBar.SuperGrid.GridCellClickEventArgs) Handles MASDRGINTENGrid.CellClick
        Dim grid As DevComponents.DotNetBar.SuperGrid.GridRow
        grid = e.GridPanel.ActiveRow
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสความเข้มข้นของยา").Value() IsNot DBNull.Value Then
            INTENTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสความเข้มข้นของยา").Value()
        Else
            INTENTxt.Text = ""
        End If
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ความเข้มข้นยา").Value() IsNot DBNull.Value Then
            INTENSITYTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ความเข้มข้นยา").Value()
        Else
            INTENSITYTxt.Text = ""
        End If
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value() = True Then
            masdrgintenStatusChk.Checked = True
        Else
            masdrgintenStatusChk.Checked = False
        End If
        connect = CONDB.NewConnection()
        If e.GridCell.GridColumn.Name = "สถานะการเปิดใช้งาน" Then
            Try
                Dim Sql As String
                connect.BeginTrans()
                Sql = "UPDATE masdrginten SET "
                If Convert.ToBoolean(CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value()) = True Then
                    Sql += "`status` = 1 "
                Else
                    Sql += "`status` = 0 "
                End If
                Sql += "WHERE `inten` = '" & INTENTxt.Text & "' ;"

                connect.ExecuteNonQuery(Sql)
                connect.CommitTrans()
            Catch ex As Exception
                connect.RollbackTrans()
                MsgBox(ex.ToString)
            End Try
        End If
        connect.Dispose()
        addMasdrginten.Enabled = False
    End Sub

    Private Sub addMasdrginten_Click(sender As Object, e As EventArgs) Handles addMasdrginten.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PADD_ = True Then
                If INTENSITYTxt.Text.ToString.Length > 0 Then
                    Dim objInsertData As New masdrginten
                    objInsertData.INTENSITY_ = INTENSITYTxt.Text
                    objInsertData.STATUS_ = masdrgintenStatusChk.Checked
                    objInsertData.insertMasdrgintenData()

                    SelectDatagridMASDRGINTEN()

                    INTENTxt.Text = ""
                    INTENSITYTxt.Text = ""
                    masdrgintenStatusChk.Checked = False
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน")
                End If
            Else
                MsgBox(PROVIDER_Check.PADDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub editMasdrginten_Click(sender As Object, e As EventArgs) Handles editMasdrginten.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PUPD_ = True Then
                If INTENTxt.Text.ToString.Length > 0 And INTENSITYTxt.Text.ToString.Length > 0 Then
                    Dim editStat As Integer
                    editStat = MsgBox("ท่านต้องการแก้ไขข้อมูลความเข้มข้นของยาดังกล่าวใช่หรือไม่", MsgBoxStyle.OkCancel)

                    If editStat = 1 Then
                        Dim objEditData As New masdrginten
                        objEditData.INTEN_ = INTENTxt.Text
                        objEditData.INTENSITY_ = INTENSITYTxt.Text
                        objEditData.STATUS_ = masdrgintenStatusChk.Checked
                        objEditData.editMasdrgintenData()

                        SelectDatagridMASDRGINTEN()

                        INTENSITYTxt.Text = ""
                        masdrgintenStatusChk.Checked = False
                    End If
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน")
                End If
                addMasdrginten.Enabled = True
            Else
                MsgBox(PROVIDER_Check.PUPDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub importExel_Click(sender As Object, e As EventArgs) Handles importExel.Click
        Dim nextform As New IMPORTEXCEL("masdrginten")
        nextform.ShowDialog()
    End Sub

    Private Sub exportExcel_Click(sender As Object, e As EventArgs) Handles exportExcel.Click
        Dim nextform As New IMPORTEXCEL("masdrginten")
        nextform.ShowDialog()
    End Sub
End Class